import { message } from "antd"
import axios from "axios"
const requrst = axios.create({
    baseURL: import.meta.env.VITE_APP_URL,
    timeout: 5000,

})
requrst.defaults.withCredentials = true

requrst.interceptors.request.use((config) => {

    return config
})

requrst.interceptors.response.use((response) => {



    return response.data

}, function (error) {
    // 超出 2xx 范围的状态码都会触发该函数。
    // 对响应错误做点什么
    let messages = ''
    let status = error.response.status
    switch (status) {
        case 422:
            messages = "验证码错误"
            break;
        case 423:
            messages = "账号注册或qq已绑定"
            break
        case 400:
            messages = "账号或密码错误"
            break
        case 424:
            messages = "未绑定的qq"
            break
        case 425:
            messages = "修改失败"
            break
        case 426:
            messages = "添加失败"
            break
        case 427:
            messages = "删除失败"
            break
        case 428:
            messages = "收藏失败"
            break
        case 429:
            messages = "取消失败"
            break
        case 500:
            messages = "服务器错误"
            break
        default:
            break;
    }
    message.error(messages)
    return Promise.reject(error);
})


export default requrst